﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

// 一个地面格子
public class Grid
{
    public int X { get; private set; }
    public int Y { get; private set; }
    // 中心点坐标
    public Vector2 CenterPos { get; private set; }

    public bool HasPlant { get { return _curPlants != null; } }

    public bool CanGrow { get { return !HasPlant && AttackLine != null; } }

    private GridMgr _gridMgr;

    // 当前种植的植物
    private PlantInScene _curPlants;
    private AttackLine _attackLine; // 所属进攻线
    public AttackLine AttackLine { get { return _attackLine; } }

    public Grid(GridMgr gridMgr, int x, int y)
    {
        X = x;
        Y = y;

        _gridMgr = gridMgr;

        CenterPos = _gridMgr.GetGridCenter(X, Y);
    }

    // 设置格子里的植物(植物主动种植，格子处于被动)
    public void SetPlant(PlantInScene plant)
    {
        _curPlants = plant;
    }
    // 设置所属进攻线(格子处于被动)
    public void SetAttackLine(AttackLine attackLine)
    {
        _attackLine = attackLine;
    }

    // 删除植物
    internal void RemovePlant()
    {
        _curPlants.RemoveFormGrid();
    }
}

